package com.lq.schoolshop.util;

import java.io.*;
import java.net.*;

/**
 * @Author
 * @Date2021/1/13 20:22
 * @Version V1.0
 * 为什么努力？想把钱都赚够，一心跳广场舞曲去。
 **/
public class IPlocalUtil {
    public static String sendPost(String url, String param)
    {
        PrintWriter out = null;
        BufferedReader in = null;
        StringBuilder result = new StringBuilder();
        try
        {
            String urlNameString = url + "?" + param;
            URL realUrl = new URL(urlNameString);
            URLConnection conn = realUrl.openConnection();
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            conn.setRequestProperty("Accept-Charset", "utf-8");
            conn.setRequestProperty("contentType", "utf-8");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            out = new PrintWriter(conn.getOutputStream());
            out.print(param);
            out.flush();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "GBK"));
            String line;
            while ((line = in.readLine()) != null)
            {
                result.append(line);
            }

        }
        catch (ConnectException e)
        {

        }
        catch (SocketTimeoutException e)
        {

        }
        catch (IOException e)
        {

        }
        catch (Exception e)
        {

        }
        finally
        {
            try
            {
                if (out != null)
                {
                    out.close();
                }
                if (in != null)
                {
                    in.close();
                }
            }
            catch (IOException ex)
            {

            }
        }
        return result.toString();
    }
}
